package com.atguigu.gmall.fastdfs;

import com.atguigu.gmall.model.user.UserInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @Author: lx
 * @Time: 9:37
 * @Description:
 */
public class JSONDemo {

    public static void main(String[] args) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        UserInfo userInfo = new UserInfo();
        userInfo.setId(123L);

        //@ResponseBody
        String string = objectMapper.writeValueAsString(userInfo);
        System.out.println(string);

        //@RequestBody
        UserInfo userInfo1 = objectMapper.readValue(string, UserInfo.class);
        System.out.println(userInfo1);

    }
}
